package com.dk.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dk.util.wx.WxUtil;
import com.xiaoleilu.hutool.io.IoUtil;

@Controller
@RequestMapping("/")
public class WxController {
	
	@RequestMapping("wx")
	@ResponseBody
	public String index(HttpServletRequest request,HttpServletResponse response) throws IOException {
		System.out.println(request.getSession().getId()+"\t"+request.getServletPath()+":"+JSON.toJSONString(request.getParameterMap(), true));
		System.out.println(IoUtil.read(request.getInputStream()));
		String echostr=request.getParameter("echostr");
		return echostr;
	}
	@RequestMapping("getUserInfo")
	@ResponseBody
	public JSONObject getUserInfo(HttpServletRequest request,HttpServletResponse response) throws IOException {
		return WxUtil.getUserInfo(WxUtil.htmlAccessToken(request.getParameter("code")));
	}
}
